package zuoye.ershouche.controller;


import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import zuoye.ershouche.common.Result;
import zuoye.ershouche.entity.User;
import zuoye.ershouche.service.UserService;

import java.util.List;

@RestController
@Api(tags = "用户路由")
public class UserController {

    @Autowired
    UserService userService;

    @GetMapping("/findUserInfo")
    @ApiOperation(value = "查询全部用户")
    public Result selectAllByPage() {
        return Result.success(userService.selectUsersAll());
    }

    @PostMapping("/addUser")
    @ApiOperation(value = "新建用户")
    public Result addUser(@RequestBody User user) {
        return Result.success(userService.insertUser(user));
    }

    @DeleteMapping("/deleteUser")
    @ApiOperation(value = "删除用户")
    public Result deleteUser(@RequestParam Integer id) {
        return Result.success(userService.deleteUserById(id));
    }

    @GetMapping("/getUserList")
    @ApiOperation(value = "获取用户列表(分页查询)")
    public Result getUserList(int pageSize, int pageNum) {
        List<User> userList =  userService.getUserList(pageSize, pageNum);
        System.out.println(userList);
        return Result.success(userList);
    }
}
